package calcmaster.calculator.util;

import java.util.EnumMap;

import calcmaster.calculator.domain.Function;
import calcmaster.calculator.domain.FunctionType;
import calcmaster.calculator.functions.AbsFunction;
import calcmaster.calculator.functions.ArccoshFunction;
import calcmaster.calculator.functions.ArcctgFunction;
import calcmaster.calculator.functions.ArcctghFunction;

public class FunctionRepository {
	private EnumMap<FunctionType, Function> functionMap;
	
	private static FunctionRepository instance = new FunctionRepository();
	
	private FunctionRepository() {
		functionMap = new EnumMap<FunctionType, Function>(FunctionType.class);
		
		functionMap.put(FunctionType.ABS, new AbsFunction());
		functionMap.put(FunctionType.ARCCOSH, new ArccoshFunction());
		functionMap.put(FunctionType.ARCCTG, new ArcctgFunction());
		functionMap.put(FunctionType.ARCCTGH, new ArcctghFunction());
		functionMap.put(FunctionType.ARCSIN, new AbsFunction());
		functionMap.put(FunctionType.ARCSINH, new ArccoshFunction());
		
		
		
		functionMap.put(FunctionType.ARCCTG, new ArcctgFunction());
		functionMap.put(FunctionType.ARCCTGH, new ArcctghFunction());
		
		functionMap.put(FunctionType.ABS, new AbsFunction());
		functionMap.put(FunctionType.ARCCOSH, new ArccoshFunction());
		functionMap.put(FunctionType.ARCCTG, new ArcctgFunction());
		functionMap.put(FunctionType.ARCCTGH, new ArcctghFunction());
		
		functionMap.put(FunctionType.ABS, new AbsFunction());
		functionMap.put(FunctionType.ARCCOSH, new ArccoshFunction());
		functionMap.put(FunctionType.ARCCTG, new ArcctgFunction());
		functionMap.put(FunctionType.ARCCTGH, new ArcctghFunction());
		
		functionMap.put(FunctionType.ABS, new AbsFunction());
		functionMap.put(FunctionType.ARCCOSH, new ArccoshFunction());
		functionMap.put(FunctionType.ARCCTG, new ArcctgFunction());
		functionMap.put(FunctionType.ARCCTGH, new ArcctghFunction());
		
		functionMap.put(FunctionType.ABS, new AbsFunction());
		functionMap.put(FunctionType.ARCCOSH, new ArccoshFunction());
		functionMap.put(FunctionType.ARCCTG, new ArcctgFunction());
		functionMap.put(FunctionType.ARCCTGH, new ArcctghFunction());
		
		functionMap.put(FunctionType.ABS, new AbsFunction());
		functionMap.put(FunctionType.ARCCOSH, new ArccoshFunction());
		functionMap.put(FunctionType.ARCCTG, new ArcctgFunction());
		functionMap.put(FunctionType.ARCCTGH, new ArcctghFunction());
		
		functionMap.put(FunctionType.ABS, new AbsFunction());
		functionMap.put(FunctionType.ARCCOSH, new ArccoshFunction());
		functionMap.put(FunctionType.ARCCTG, new ArcctgFunction());
		functionMap.put(FunctionType.ARCCTGH, new ArcctghFunction());
		
		functionMap.put(FunctionType.ABS, new AbsFunction());
		functionMap.put(FunctionType.ARCCOSH, new ArccoshFunction());
		functionMap.put(FunctionType.ARCCTG, new ArcctgFunction());
		functionMap.put(FunctionType.ARCCTGH, new ArcctghFunction());
		
		functionMap.put(FunctionType.ABS, new AbsFunction());
		functionMap.put(FunctionType.ARCCOSH, new ArccoshFunction());
		functionMap.put(FunctionType.ARCCTG, new ArcctgFunction());
		functionMap.put(FunctionType.ARCCTGH, new ArcctghFunction());
	}
	
	public static FunctionRepository getInstance() {
		return instance;
	}
	
	public boolean isFunctionListed(String functionName) {
		FunctionType functionType = FunctionType.getFromName(functionName);
		
		return (functionMap.get(functionType) != null);
	}
	
	public Function getFunction(FunctionType functionType) {
		return functionMap.get(functionType);
	}

}
